/*
jQuery.fn.center = function () {
    this.css("position","relative");
    this.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + "px");
    // this.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + "px");
    return this;
}
*/

jQuery.fn.center = function () {
  var h = $(window).height();
  var total_h = h-125-20-57;
  var el_h = this.outerHeight();
  
  var jarak = (total_h - el_h)/2;
  if(jarak < 140){ jarak = 140; }
  // console.log(total_h);
  // console.log(el_h);
  
  this.css('position', 'relative');
  this.css('top', jarak+'px');
  // this.css('margin-top', '-'+(total_h/2)+'px');
}

jQuery.fn.portfolio_center = function () {
  var h = $(window).height();
  var total_h = h-125-20-57-55;
  var el_h = this.outerHeight();
  
  var jarak = (total_h - el_h)/2;
  if(jarak < 0){ jarak = 140; }
  // console.log(total_h);
  // console.log(el_h);
  
  this.css('position', 'relative');
  this.css('top', jarak+'px');
  // this.css('margin-top', '-'+(total_h/2)+'px');
}

function grayscale(src) {
	var supportsCanvas = !!document.createElement('canvas').getContext;
	if (supportsCanvas) {
		var canvas = document.createElement('canvas'), 
		context = canvas.getContext('2d'), 
		imageData, px, length, i = 0, gray, 
		img = new Image();
		
		img.src = src;
		canvas.width = img.width;
		canvas.height = img.height;
		context.drawImage(img, 0, 0);
			
		imageData = context.getImageData(0, 0, canvas.width, canvas.height);
		px = imageData.data;
		length = px.length;
		
		for (; i < length; i += 4) {
			gray = px[i] * .3 + px[i + 1] * .59 + px[i + 2] * .11;
			px[i] = px[i + 1] = px[i + 2] = gray;
		}
				
		context.putImageData(imageData, 0, 0);
		return canvas.toDataURL();
	} else {
		return src;
	}
}
